package com.reger.l2cache.bloomfilter.hash;

import com.reger.l2cache.bloomfilter.Hash;

public class BernsteinHash implements Hash {

	private final long cap;

	public BernsteinHash(long cap) {
		super();
		this.cap = cap;
	}

	@Override
	public long hash(String value) {
		long hash = 0;
		int index;
		for (index = 0; index < value.length(); ++index) {
			hash = 33 * hash + value.charAt(index);
		}
		return hash & (cap - 1);
	}

}
